/* 封装文章接口 */

import axios from '@/utils/request'

/**
 * 获取文章列表数据
 *
 * @export
 * @param {*} id  频道ID
 * @param {*} timestamp 时间戳
 * @return {*}
 */
export function getArticle(id, timestamp) {
  return axios({
    url: '/v1_0/articles',
    // get 方式，数据写在params中
    params: {
      channel_id: id,
      timestamp
    }
  })
}

/**
 * 对文章不喜欢(不感兴趣)
 * @param {*} target 不喜欢的文章id
 * @returns
 */
export const disLikeArticle = target => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target
    }
  })
}

/**
 * 举报文章
 * @param {*} target 举报的文章id
 * @param {*} type 举报类型
 * @returns
 */
export const reportArticle = (target, type) => {
  return axios({
    method: 'post',
    url: '/v1_0/article/reports',
    data: {
      target,
      type
    }
  })
}

/**
 * 获取新闻详情
 * @param {*} id 文章id
 * @returns
 */
export const getArticleInfo = id => {
  return axios({
    url: `/v1_0/articles/${id}`
  })
}

/**
 * 关注用户
 * @param {*} target 用户id
 * @returns
 */
export const following = target => {
  return axios({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 * 取关
 * @param {*} target 作者id
 * @returns
 */
export const delFollowing = target => {
  return axios({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 获取文章评论
 * @param {*} source 文章id
 * @param {*} offset 评论id
 * @returns
 */
export const getComment = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对文章进行评论
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @returns
 */
export const toComment = (target, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      content
    }
  })
}

/**
 * 对评论点赞
 * @param {*} target 点赞的评论id
 * @returns
 */
export const likeComment = target => {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target
    }
  })
}

/**
 * 取消对评论点赞
 * @param {*} target 评论id
 * @returns
 */
export const delLikeComment = target => {
  return axios({
    url: `/v1_0/comment/likings/${target}`,
    method: 'DELETE'
  })
}

/**
 * 获取评论回复
 * @param {*} source 评论id
 * @param {*} offset 获取评论数据的偏移量
 * @returns
 */
export const getCommentReply = (source, offset) => {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      limit: 10
    }
  })
}

/**
 * 对评论进行评论
 * @param {*} target 评论id
 * @param {*} id 文章id
 * @param {*} content 文字内容
 * @returns
 */
export const commentToComment = (target, id, content) => {
  return axios({
    url: '/v1_0/comments',
    method: 'post',
    data: {
      target,
      art_id: id,
      content
    }
  })
}
